#ifndef CONIN_BASE_ROBOT_KERNEL_IMPLEMENTATION_H
#define CONIN_BASE_ROBOT_KERNEL_IMPLEMENTATION_H

#include "robotkernel.h"
#include "coopsched.h"
#include "opmodeid.h"

namespace cnc {

	namespace base {

		class RobotKernelImpl : public RobotKernel, public KernelControl, public KernelSetup
		{
			typedef CooperativeScheduler<OperationModeID, CooperativeTask> CooperativeScheduler_;
			CooperativeScheduler_ scheduler_;
		protected:
			RobotKernelImpl()
			{
			}
		public:
			static RobotKernelImpl &instance()
			{
				static RobotKernelImpl object;
				return object;
			}
			virtual KernelControl *getKernelControl()
			{
				return this;
			}
			virtual KernelSetup *getKernelSetup()
			{
				return this;
			}
		private:
			virtual bool start()
			{
				return scheduler_.start();
			}
			virtual bool execute()
			{
				scheduler_.selectMode(OPMODE_SETUP);
				return scheduler_.execute();
			}
			virtual bool stop()
			{
				return scheduler_.stop();
			}
		private:
			virtual void addTask(CooperativeTask *backgroundTask)
			{
				scheduler_.addTask(backgroundTask);
			}
			virtual void addMode(OperationModeID modeID, CooperativeTask *operationMode)
			{
				scheduler_.addMode(modeID, operationMode);
			}
			virtual void selectMode(OperationModeID modeID)
			{
				scheduler_.selectMode(modeID);
			}
		};

	} // namespace base

} // namespace cnc

#endif

